<?php
class Kaoshiset_ctl extends Ctl{
    function __construct(){
    }
    function main(array $xxfget) {
        $this::sessver();
        $type=!empty($_POST['type'])?$_POST['type']:false;
        $type=!empty($xxfget['type'])?$xxfget['type']:$type;
        if(!$type){
            $result=xdb::getInstance()->getarray('select * from kaoshi');
            $this::show('kaoshiset',compact('result'));
        }elseif($type=="add"){
            $kname=$_POST['kname'];
            $term=$_POST['term'];
            $array=array();
            $array2=array();
            $array['uid']=XXF_UID;
            $array['kname']=$kname;
            $array['term']=$term;
            $array['status']="等待";
            $array2['kname']=$kname;
            $array2['term']=$term;
            xdb::getInstance()->indb("kaoshi", $array, $array2);
            echo 1;
        }elseif($type=="jihuo"){
            $id=$_POST['id'];
            $array=array();
            $array2=array();
            $array['status']='激活';
            $array2['id']=$id;
            xdb::getInstance()->query("update kaoshi set status='等待'");
            if($id!="0")
            xdb::getInstance()->updb("kaoshi", $array, $array2);
            echo 1;
        }elseif($type=="tongji"){
            $id=$xxfget['id'];
            $result=xdb::getInstance()->getarray("select *,count(1) as num from ksscore where kid=$id group by kcname,cname ");
            //$result=xdb::getInstance()->getarray("select * from kaoshi as k,ksscore as ks where k.id=ks.kid and k.id=$id");
            $this->show("kaoshiset_tongji",compact('result'));
        }elseif($type=="term"){
            $id=$xxfget['kid'];
            $cname=urldecode($xxfget['cname']);
            $kcname=urldecode($xxfget['kcname']);
            $result=xdb::getInstance()->getarray("select * from ksscore where kid=$id and kcname like '$kcname' and cname like '$cname'");
            $this->show("kaoshiset_term",compact('result'));
        }
    }
}